package com.mintandleaf.webkits.validator;

/**
 * Validator for numeric value
 * @author teguhh
 */
public class NumberValidator extends BaseValidator{

    /**
     * Construct number validator with
     * standar message error
     **/
    public NumberValidator(){
        setErrorMessage("Failed It's not a number");
    }
    /**
     * Construct the Number Validator with specified 
     * error message
     * @param paramErrorMessage
     **/
    public NumberValidator(String paramErrorMessage){
        setErrorMessage(paramErrorMessage);
    }
    /**
     *
     * @param value object to be validate
     * @return true on successfull validation
     **/
    @Override
    public boolean validate(Object value) {
        String number=String.valueOf(value);
        try{
                /*
                 *  using an integer u can overide this function to create your
                 *  own validation methods
                 */
                Integer intNumber=Integer.parseInt(number);
                return true;
        }catch(NumberFormatException exc){
            return false;
        }
    }

}
